package cl.orangepeople.whyem.portal.negotiations.beans.historic;

import cl.orangepeople.whyem.portal.backend.api.NegotiationsService;
import cl.orangepeople.whyem.portal.backend.dto.negotiations.NegotiationDataBean;
import cl.orangepeople.whyem.portal.backend.dto.negotiations.NegotiationDataDetails;
import cl.orangepeople.whyem.portal.negotiations.utils.whyemUtils;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.annotation.Resource;
import javax.inject.Named;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.util.Assert;

@Named("historicDetailBean")
@Scope("session")
public class HistoricDetailBean implements Serializable {
    private static Logger logger = LoggerFactory.getLogger(HistoricDetailBean.class);
    @Resource(name = "negotiationService")
    private NegotiationsService negotiationsService;
    private NegotiationDataDetails negotiationDataDetails;
    private Date currentDate;

    public String initLoadNegotiationDetailBean(BigDecimal paymentNumber) {
        Assert.notNull(paymentNumber);
        NegotiationDataBean negotiationDetails = negotiationsService.getNegotiationDetail(whyemUtils.getNegotiationInputParameter(whyemUtils.getUserClientID(), paymentNumber));
        Assert.notNull(negotiationDetails);
        this.negotiationDataDetails = negotiationDetails.getNegotiationDetail();
        this.currentDate = new Date();
        logger.info("Datos antes de partir Data {}", ToStringBuilder.reflectionToString(negotiationDataDetails, ToStringStyle.SIMPLE_STYLE));
        logger.info("Datos antes de partir Date {}", currentDate.toString());
        return "negotiationDetail";
    }

    public NegotiationDataDetails getNegotiationDataDetails() {
        return negotiationDataDetails;
    }

    public void setNegotiationDataDetails(NegotiationDataDetails negotiationDataDetails) {
        this.negotiationDataDetails = negotiationDataDetails;
    }

    public Date getCurrentDate() {
        return currentDate;
    }

    public void setCurrentDate(Date currentDate) {
        this.currentDate = currentDate;
    }
}
